package com.anis.project.medcare.command.handler;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;

import com.anis.project.medcare.editors.ReportEditor;

public class PrintDocument implements IHandler {

	@Override
	public void addHandlerListener(IHandlerListener handlerListener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IEditorPart editorPart = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		ReportEditor reportEditor = (ReportEditor) editorPart;
		reportEditor.printDocument();
		return null;
	}

	@Override
	public boolean isEnabled() {
		IEditorPart editorPart = null;
		if (null != PlatformUI.getWorkbench().getActiveWorkbenchWindow())
			editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
					.getActivePage().getActiveEditor();
		return (null != editorPart && editorPart instanceof ReportEditor);
	}

	@Override
	public boolean isHandled() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void removeHandlerListener(IHandlerListener handlerListener) {
		// TODO Auto-generated method stub

	}

}
